﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.Generic;
using Twilight.TwitterData;
using System.Windows.Media.Imaging;
using System.ComponentModel;
using Twilight.Views;

namespace Twilight.ViewModels
{
    public class ListViewModel : BaseViewModel
    {
        public List<Tweet> Tweets { get; private set; }

        protected override void LoadData()
        {
            if (IsDesignTime())
            {
                Tweets = new List<Tweet>() {new Tweet() { text = "This is some design time data for you to work with.", created_at = DateTime.Now.ToString("ddd MMM dd HH:mm:ss zzz yyyy", null), source = "code" }};
            }
            base.LoadData();
        }

        protected override void UpdateTweets(Tweet[] tweets)
        {
            if (!loaded)
            {
                loaded = true;

                User u = tweets[0].user;

                Followers = string.Format("{0} followers", u.followers_count);
                PropertyUpdated("Followers");

                LoadAvatar(new Uri(u.profile_image_url));

                VisualStateManager.GoToState(RootVisual, "Loaded", true);
            }

            Tweets = new List<Tweet>(tweets);
            PropertyUpdated("Tweets");
        }
    }
}
